/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 * Store a group of oject, with each ojbect has a id
 * @author: jin Chen 
 * @date: Oct 2, 2003$
 * @version: 1.0
 */
package edu.psu.geovista.app.pcp.toolkits.group;

import java.util.*;

public class ObjectGroup {
    protected Hashtable groups=new Hashtable();
    /**
     * Not guarantee each time the objects returned are same if given same index since the data model is Hashtable, not List
     * This is usually used to get all ojbects without concern about their index
     * A better way is to use iterator
     * @return
     */
    /*public Object getByIndex(int index) {
        return null; //not complete
    }*/

    public Object getByID(Object id){
        return groups.get(id);

    }
     public Enumeration keys(){
         return groups.keys() ;
     }
    /**
     *
     * @return   a sorted list ids.
     */
     public ArrayList getSortGroupIdList(){
        ArrayList list=Collections.list(keys());
        Collections.sort(list);
        return list;
    }
    public Enumeration elements(){
        return this.groups.elements() ;
    }
     public Iterator iterator() {
         return this.groups.values().iterator() ;
     }
     /**
      * How to sort depend on the compare() of the object that stored in groups
      * @return   a sorted list of the elements
      */
     public ArrayList getIndexSortList(){
         ArrayList al=Collections.list(this.groups.elements()) ;
         Collections.sort(al);
         return al;

     }
    public int size() {
        return this.groups.size() ;
    }

    public Object remove(Object key){
        return this.groups.remove(key);
    }
}
